package com.youxin.busfoundation.bean.classify;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.aspectj.weaver.tools.cache.AsynchronousFileCacheBacking.ClearCommand;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.youxin.busfoundation.bean.BaseRequestBean;

/**
 * 输出类别
 * @author yingde.cao
 *
 */
@JsonInclude( JsonInclude.Include.NON_NULL)
public class ResponseClassifyBean implements Serializable,Cloneable{
	
    /**
	 * 
	 */
	private static final long serialVersionUID = 19241388325L;

	/** 唯一ID */
    private Integer uid;

    /** 行业名称 */
    private String name;

    /**  */
    private Integer pid;


    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public Integer getPid() {
        return pid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

    private List<ResponseClassifyBean> childs;

	public List<ResponseClassifyBean> getChilds() {
		
		return childs;
	}

	public void addChild(ResponseClassifyBean bean){
		if(childs==null){
			childs=new ArrayList<>(20);
		}
		childs.add(bean);
	}
    
	@JsonIgnore
    public boolean isTopLevel()
    {
    	return pid.intValue()==0?true:false;
    }
    
	
    public boolean isChildInItem(ResponseClassifyBean topItem)
    {
    	return pid.intValue()==topItem.getUid().intValue();
    }
    
    public ResponseClassifyBean isChildInItems(List<ResponseClassifyBean> topItems)
    {
    	for(ResponseClassifyBean item:topItems)
    	{
    		if(isChildInItem(item))
    		{
    			return item;
    		}
    	}
    	return null;
    }
    
    public void clear()
    {
    	if(childs!=null)
    	{
    		childs.clear();
    	}
    }
    
    /* (non-Javadoc)
     * @see java.lang.Object#clone()
     */
    @Override
    public Object clone() throws CloneNotSupportedException {
    	// TODO Auto-generated method stub
    	return super.clone();
    }
    
    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
    	// TODO Auto-generated method stub
    	return uid+":"+String.valueOf(name)+":"+String.valueOf(pid);
    }
   
}
